import Vue from 'vue'
import Router from 'vue-router'
import ManageMain from '../pages/manageMain.vue'
import DoctorMain from '../pages/doctorMain.vue'
import UserMain from '../pages/userMain.vue'
import HomeMain from '../pages/homeMain.vue'
import Login from '../pages/login.vue'
import Register from '../pages/register.vue'
// import Index from '../index.vue'
// import Home from '../pages/Index/home.vue'

let manageFiles = require.context('../pages/manager', true, /[a-zA-Z]\.vue$/)
let userFiles = require.context('../pages/user', true, /[a-zA-Z]\.vue$/)
let homeFiles = require.context('../pages/home', true, /[a-zA-Z]\.vue$/)
let doctorFiles = require.context('../pages/doctor', true, /[a-zA-Z]\.vue$/)


// console.log(require.context)
// console.log(require.prototype)
// console.log('files', files.keys())

let manageRouter = manageFiles.keys().map(item => {
    return {
        path: item.slice(1, -4),
        name: item.slice(1, -4),
        component: () => import(`../pages/manager${item.slice(1)}`),
        mate: {
            title: manageFiles(item).default.comName
        }
    }
})

let userRouter = userFiles.keys().map(item => {
    return {
        path: '/user' + item.slice(1, -10),
        name: '/user' + item.slice(1, -10),
        component: () => import(`../pages/user${item.slice(1)}`),
        mate: {
            title: userFiles(item).default.comName,
            sort: userFiles(item).default.comSort
        }
    }
})

let homeRouter = homeFiles.keys().map(item => {
    return {
        path: '/home' + item.slice(1, -10),
        name: '/home' + item.slice(1, -10),
        component: () => import(`../pages/home${item.slice(1)}`),
        mate: {
            title: homeFiles(item).default.comName,
            sort: homeFiles(item).default.comSort
        }
    }
})

let doctorRouter = doctorFiles.keys().map(item => {
    return {
        path: '/doctor' + item.slice(1, -10),
        name: '/doctor' + item.slice(1, -10),
        component: () => import(`../pages/doctor${item.slice(1)}`),
        mate: {
            title: doctorFiles(item).default.comName,
            sort: doctorFiles(item).default.comSort
        }
    }
})


// console.log('userFile132', userRouter)

// console.log(fileRoutes)
// console.log(fileRoutes)
Vue.use(Router)

let routes = new Router({
    routes: [
        {
            path: '/manageMain',
            name: 'manageMain',
            component: ManageMain,
            children: manageRouter
        },
        {
            path: '/doctorMain',
            name: 'doctorMain',
            component: DoctorMain,
            children:doctorRouter
        },
        {
            path: '/userMain',
            name: 'userMain',
            component: UserMain,
            children: userRouter
        },
        {
            path: '/homeMain',
            name: 'homeMain',
            component: HomeMain,
            children: homeRouter
        },
        {
            path: '/login',
            name: 'login',
            component: Login
        },
        {
            path: '/register',
            name: 'register',
            component: Register
        },
        {
            path: '/',
            redirect: '/home/home'
        },
        {
            path: '/editPassword',
            name: 'editPassword',
            component: ()=> import('../components/editPassword.vue')
        },
        {
            path: '/doctorPassword',
            name: 'doctorPassword',
            component: ()=> import('../components/doctorPassword.vue')
        },

    ]
})

export default routes
